<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>params传参</title>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
  </head>
  <body>
    <div id="app">
      <button @click="goStart">跳转</button>
      <router-view></router-view>
    </div>
    <script>
      // 定义user组件
      var user = {
        template: "<p>用户名：{{ this.$route.params.name }}</p>",
      };
      var router = new VueRouter({
        routes: [{ path: "/user", name: "user", component: user }],
      });
      var vm = new Vue({
        el: "#app",
        methods: {
          goStart() {
            this.$router.push({ name: "user", params: { name: "user123" } });
          },
        },
        router,
      });
    </script>
  </body>
</html>
